package Client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

import Model.Payload;

public class PayloadClientServer {
	private ServerSocket serverSocket;
	private Socket server;
	
	public PayloadClientServer() {		
		try {
			serverSocket = new ServerSocket(1235);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public Payload readPayloadObject() {
		try {
			server = serverSocket.accept();
			ObjectInputStream objectInputStream = new ObjectInputStream(server.getInputStream());
			Payload payload = (Payload) objectInputStream.readObject();
			objectInputStream.close();
			
			server.close();
			
			return payload;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}			
		
		return null;
	}
}
